package com.dyw.ycgovfinance.adapter.chart;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dyw.ycgovfinance.R;
import com.dyw.ycgovfinance.bean.FinanceBean;

import java.util.List;

/**
 * Created by Administrator on 2017/6/21.
 */

public class FinanceAdapter extends BaseAdapter {

    private Context context;
    private List<FinanceBean> financeBeanList;

    public FinanceAdapter(Context context, List<FinanceBean> financeBeanList) {
        this.context = context;
        this.financeBeanList = financeBeanList;
    }

    @Override
    public int getCount() {
        return financeBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return financeBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder myViewHolder = null;
        if (convertView == null) {
            myViewHolder = new MyViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_finance_layout, null);
            myViewHolder.lyItem = (LinearLayout) convertView.findViewById(R.id.ly_item);
            myViewHolder.tvDistrict = (TextView) convertView.findViewById(R.id.tv_district);
            myViewHolder.tvYearBuget = (TextView) convertView.findViewById(R.id.tv_year_buget);
            myViewHolder.tvMoney = (TextView) convertView.findViewById(R.id.tv_money);
            myViewHolder.tvAccountHas = (TextView) convertView.findViewById(R.id.tv_account_has);
            myViewHolder.tvAccountMore = (TextView) convertView.findViewById(R.id.tv_account_more);

            convertView.setTag(myViewHolder);
        } else {
            myViewHolder = (MyViewHolder) convertView.getTag();
        }
        if (position % 2 == 0) {
            myViewHolder.lyItem.setBackgroundColor(Color.parseColor("#AAEBEBEB"));
        } else {
            myViewHolder.lyItem.setBackgroundColor(Color.parseColor("#ffffff"));
        }
        myViewHolder.tvDistrict.setText(financeBeanList.get(position).getArea() + "");
        myViewHolder.tvYearBuget.setText(financeBeanList.get(position).getYearBudget() + "");
        myViewHolder.tvMoney.setText(financeBeanList.get(position).getCumulateAmount() + "");
        myViewHolder.tvAccountHas.setText(financeBeanList.get(position).getYearBudgetPercent() + "");
        myViewHolder.tvAccountMore.setText(financeBeanList.get(position).getAmplificationPercent() + "");
        return convertView;
    }

    class MyViewHolder {
        private LinearLayout lyItem;
        private TextView tvDistrict;
        private TextView tvYearBuget;
        private TextView tvMoney;
        private TextView tvAccountHas;
        private TextView tvAccountMore;
    }
}
